package com.lanyun.carworld.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lanyun.carworld.model.entity.UserRole;
import com.lanyun.carworld.mapper.UserRoleMapper;
import com.lanyun.carworld.service.UserRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
* @author 29074
* @description 针对表【user_role(用户角色表)】的数据库操作Service实现
* @createDate 2024-06-13 21:49:54
*/
@Service
@Slf4j
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole>
    implements UserRoleService{


    /**
     * 检查用户是否有角色,没有则插入数据库
     * @param userId
     */
    @Override
    public void checkUserRole(Long userId) {

        QueryWrapper<UserRole> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("userId", userId);


        UserRole userRole = this.getOne(queryWrapper);
        if(userRole == null){
            UserRole role = new UserRole();
            role.setUserId(userId);
            log.info("用户{}没有角色，插入角色",userId);
            this.save(role);
        }

    }
}




